<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>登录商城</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      html,
      body {
        width: 100%;
        height: 100%;
      }
      a {
        text-decoration: none;
      }
      #box {
        height: 100%;
        width: 100%;
        background: rgb(241, 241, 241);
      }
      #top {
        box-sizing: border-box;
        width: 960px;
        height: 48px;
        margin: auto;
        /* background: pink; */
        padding-top: 13px;
      }
      img {
        display: block;
      }
      .logo {
        width: 110px;
      }
      .left {
        float: left;
      }
      .top-logo {
        background: url(./imgs/fgx.png) no-repeat right;
        /* border-right: 1px solid #888; */
        padding-right: 20px;
      }
      .top-text {
        font-weight: bold;
        margin-left: 20px;
      }
      #button {
        box-sizing: border-box;
        width: 960px;
        height: 100px;
        margin: auto;
        /* background: pink; */
        padding-top: 25px;
      }
      #button p {
        text-align: center;
      }
      #button p span {
        margin: 0 20px;
      }
      #text {
        width: 100%;
        height: 82%;
        margin: auto;
        background: #fff;
        box-sizing: border-box;
        padding-top: 60px;
      }
      #button p:nth-child(1) {
        color: #999;
        font-size: 14px;
      }
      #button p:nth-child(2) {
        color: rgba(0, 0, 0, 0.3);
        margin-top: 15px;
        font-size: 12px;
      }
      .text {
        width: 960px;
        /* border: 1px solid red; */
        height: 500px;
        margin: auto;
      }
      .text p {
        font-size: 28px;
        text-align: center;
      }
      .text-dl {
        /* height: 465px; */
        width: 100%;
        margin-top: 60px;
      }
      .text-dl .ewm {
        width: 50%;
      }
      .ewm img {
        width: 160px;
        height: 160px;
        margin: auto;
        border: 20px solid #f7f7f7;
      }
      .ewm p {
        text-align: center;
        font-size: 12px;
        color: #888;
      }
      .text-dl span {
        height: 300px;
        border: 1px solid rgba(0, 0, 0, 0.1);
        display: block;
        float: left;
      }
      .dl {
        margin-left: 70px;
      }
      .dl div {
        width: 350px;
        height: 50px;
        border: none;
        background: rgba(0, 0, 0, 0.1);
        margin-bottom: 20px;
        border-radius: 20px;
      }
      .dl input {
        width: 300px;
        height: 50px;
        border: none;
        margin: auto;
        margin-left: 20px;
        background: none;
        outline: none;
      }
      .dl input:hover #t1 {
        border: 1px solid aqua;
      }
      .dl input:hover ~ #t1 {
        border: 1px solid aqua;
      }
      #t2 {
        position: relative;
      }
      .pass {
        position: absolute;
        right: 20px;
        width: 25px;
        height: 25px;
        top: 12px;
      }
      #use {
        color: red;
        font-size: 12px;
        display: none;
      }
      #text .btn {
        background: rgb(235, 166, 170);
        height: 50px;
        width: 350px;
        cursor: not-allowed;
      }
      .btn p {
        color: #fff;
        font-size: 16px;
        text-align: center;
        line-height: 50px;
      }
      .dl .nav {
        background: none;
        margin: 0;
      }
      .nav .nav-p {
        font-size: 12px;
        line-height: 50px;
      }
      .nav a {
        color: #007dff;
        margin: 0 10px;
      }
      b {
        font-weight: normal;
      }
      .dl .link {
        background: none;
        margin: 0;
      }
      .link span {
        background: rgba(0, 0, 0, 0.1);
        background: url(./imgs/ic_third_qq.svg) no-repeat;
        background-size: cover;
        display: block;
        width: 30px;
        height: 30px;
        border-radius: 50%;
        cursor: pointer;
        float: left;
        margin-left: 66px;
      }
      .link span:nth-child(2) {
        background: url(./imgs/ic_third_weixin.svg) no-repeat right;
        background-size: cover;
      }
      .link span:nth-child(3) {
        background: url(./imgs/ic_third_alipay.svg) no-repeat right;
        background-size: cover;
      }
      .link span:hover {
        box-shadow: 10px -10px 50px #888888;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div id="top">
        <div class="left top-logo">
          <img src="./imgs/HUAWEI.svg" alt="" class="logo" />
        </div>
        <img src="./imgs/" alt="" />
        <div class="left top-text">
          <p>华为商城</p>
        </div>
      </div>

      <div id="text">
        <div class="text">
          <p>华为账号登录</p>
          <div class="text-dl">
            <div class="left ewm">
              <img src="./imgs/20220329180313.png" alt="" />
              <p>若您使用华为手机，请进入“设置”>“华为帐号”扫码登录。</p>
            </div>
            <span></span>
            <div class="left dl">
              <form>
                <p id="use">!检查手机号码</p>
                <div id="t1">
                  <input type="text" placeholder="手机号" class="user" />
                </div>
                <br />
                <div id="t2">
                  <input type="password" placeholder="密码" class="passi" /><img
                    class="pass"
                    src="./imgs/ic_password_eyeoff.svg"
                    alt="0"
                  />
                </div>
                <br />
              </form>
              <div class="btn">
                <p>登录</p>
              </div>
              <div class="nav">
                <p class="nav-p">
                  <a href="register.html">注册</a><b>|</b>
                  <a href="">忘记密码</a><b>|</b>
                  <a href="">遇到问题</a>
                </p>
              </div>
              <div class="link">
                <span></span>
                <span></span>
                <span></span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div id="button">
        <p>
          华为帐号用户协议 <span>|</span> 关于华为帐号与隐私的声明
          <span>|</span> 常见问题 <span>|</span> Cookies
        </p>
        <p>华为帐号 版权所有 © 2011-2022</p>
      </div>
    </div>
  </body>
  <script>
    let eyeo = document.querySelector(".pass");
    let t2 = document.querySelector("#t2>input");
    eyeo.onclick = function () {
      if (eyeo.alt == 0) {
        eyeo.src = "./imgs/ic_password_eyeon.svg";
        eyeo.alt = 1;
        t2.type = "text";
        return;
      }
      eyeo.src = "./imgs/ic_password_eyeoff.svg";
      t2.type = "password";
      eyeo.alt = 0;
    };
    let user = document.querySelector(".user");
    let pass = document.querySelector(".passi");
    let inp = document.querySelectorAll("input");
    let btn = document.querySelector(".btn");
    let test_tel =
      /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
    let tr = false;
    user.onblur = function () {
      if (test_tel.test(user.value)) {
        document.getElementById("use").style.display = "none";
        tr = true;
      } else {
        document.getElementById("use").style.display = "block";
        tr = false;
      }
    };
    inp.forEach((res) => {
      res.oninput = function () {
        // console.log(user.value,pass.value)
        if (user.value != "" && pass.value != "") {
          btn.style.background = "#ca141d";
          btn.style.cursor = "pointer";
        } else {
          btn.style.background = "rgb(235, 166, 170)";
          btn.style.cursor = "not-allowed";
        }
      };
    });
    btn.onclick = function () {
      if (tr) {
        let a = "http://phpclub.org.cn:8080/api" + "/user/login";
        let xhr = new XMLHttpRequest();
        xhr.open("post", a);
        xhr.setRequestHeader(
          "Content-Type",
          "application/x-www-form-urlencoded"
        );
        xhr.send(`mobile=${user.value}&password=${pass.value}`);
        xhr.onreadystatechange = function () {
          if (xhr.readyState == 4 && xhr.status == 200) {
            let resp = JSON.parse(xhr.responseText);
            console.log(resp)
            console.log(resp.code)
            console.log(resp.code==0)
            console.log(xhr.responseText.code==0)
            console.log(xhr.responseText.code)
            // 目前服务端返回的是普通字符串
            if (resp.code != 0) {
              alert(resp.code[0]);
              return;
            }
            localStorage.setItem("huaweiName", resp.data.nickname);
            localStorage.setItem("huaweiID", resp.data.id);
            let urlS=localStorage.getItem("urlS")
            localStorage.removeItem("urlS")
            if(urlS){
              location.href=urlS
              return
            }
            alert("登录成功")
            location.href="index.html"
          }
        };
      }
    };
  </script>
</html>
